package com.luhuiguo.cms.server.web;

import java.io.ByteArrayOutputStream;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Component;
import org.springframework.web.servlet.view.AbstractView;

import com.luhuiguo.cms.server.entity.Attachment;

@Component("attachment")
public class AttachmentView extends AbstractView {

    protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        Attachment attachment = (Attachment) model.get("attachment");

        setContentType(attachment.getMimeType());

        ByteArrayOutputStream baos = createTemporaryOutputStream();

        baos.write(attachment.getContent().getBytes());

        writeToResponse(response, baos);

    }

}
